import { ref } from 'vue'

export function useModal(options?: { onOpen?: () => void; onClose?: () => void }) {
  const showModal = ref(false)

  const openModal = () => {
    showModal.value = true
    if (options && !!options.onOpen) {
      options.onOpen()
    }
  }

  const closeModal = () => {
    setTimeout(() => {
      if (options && !!options.onClose) {
        options.onClose()
      }
    }, 350)
    showModal.value = false
  }

  return {
    state: showModal,
    open: openModal,
    close: closeModal
  }
}
